home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUTORC.ZIP / TUT4.C < prev    next >
C/C++ Source or Header  |  1994-10-30  |  3KB  |  107 lines

  1. /*
  2.   tut4.c
  3.   10/30/94
  4.   from tutprog4.pas
  5.   Adapted from Denthor's tutprog4.pas
  6.   Translated into C, from Denthor's VGA Trainer, by
  7.   Steve Pinault, scp@ohm.att.com
  8.   Compiled with Microsoft Visual C++ 1.5 (Microsoft C 8.0)
  9.   To compile:
  10.   First compile the subroutines in tutsubs.c with the batch file 
  11.   cltutsub.bat
  12.   Then compile any of the tutor programs with the batch file
  13.   cltut.bat
  14.   Example: C:>cltutsub
  15.            C:>cltut tut4.c
  16.            to compile this program.
  17. */
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <dos.h>
  22. #include <math.h>
  23. #include <conio.h>
  24. #include <graph.h>
  25. #include <bios.h>
  26. #include <string.h>
  27. #include "tutheadr.h"
  28.  
  29.  
  30.  
  31. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  32. // Procedure BlockMove;
  33. // This tests various ways of moving a block around the screen }
  34. void BlockMove(int incr)
  35. {
  36.   int loop1,loop2,loop3;
  37.   // Draw block to VGA w/o flipping:
  38.   for(loop1=1;loop1<=50;loop1++)
  39.   {
  40.     for(loop2=1;loop2<=50;loop2++)
  41.       for(loop3=1;loop3<=50;loop3++)
  42.         PutPixel (loop1+loop2,loop3,32,VGA);
  43.     Cls(0,VGA);
  44.   }
  45.  
  46.   // Draw block to Virtual Screen, then flips it to VGA:
  47.   for(loop1=1;loop1<=100;loop1++)
  48.   {
  49.     for(loop2=1;loop2<=50;loop2++)
  50.       for(loop3=1;loop3<=50;loop3++)
  51.         PutPixel (loop1+loop2,loop3,32,Vaddr);
  52.     Flip2(Vaddr,VGA);
  53.     Cls(0,Vaddr);
  54.   }
  55.  
  56.   // Draw block to Virtual Screen, waits for retrace, then flips it to VGA:
  57.   for(loop1=1;loop1<=200;loop1+=incr)
  58.   {
  59.     for(loop2=1;loop2<=50;loop2++)
  60.       for(loop3=1;loop3<=50;loop3++)
  61.         PutPixel (loop1+loop2,loop3,32,Vaddr);
  62.     WaitRetrace();
  63.     Flip2(Vaddr,VGA);
  64.     Cls(0,Vaddr);
  65.   }
  66. }
  67.  
  68. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  69. // Procedure PatternDraw;
  70. // This test the speed of flipping by drawing two patterns and flipping them
  71. void PatternDraw()
  72. {
  73.   int loop1,loop2;
  74.  
  75.   for(loop1=0;loop1<=100;loop1++)
  76.     for(loop2=0;loop2<=100;loop2++)
  77.       PutPixel (loop1,loop2,(unsigned char)loop1,Vaddr);  
  78.   Flip2(Vaddr,VGA);
  79.  
  80.   for(loop1=0;loop1<=100;loop1++)
  81.     for(loop2=0;loop2<=100;loop2++)
  82.       PutPixel (loop1,loop2,(unsigned char)loop2,Vaddr);  
  83.   Flip2(Vaddr,VGA);
  84. }
  85.  
  86. void main()
  87. {
  88.   int c;
  89.   int incr;
  90.   VirtPtr=&Virtual[0];
  91.   Vaddr = FP_SEG(VirtPtr);
  92.   _clearscreen(_GCLEARSCREEN);
  93.   incr=1;
  94.   SetMCGA();
  95.   Cls (0,Vaddr); 
  96.   BlockMove(incr);
  97.  
  98.   while(1)
  99.   {
  100.     PatternDraw();
  101.     c=_bios_keybrd(_KEYBRD_READY);
  102.     if(c)break;
  103.   }
  104.   getch();
  105.   SetText();
  106. }
  107.